package com.siecom.module;

import com.siecom.tool.ByteTool;

public class EMVAPPLIST {
    public static final int MAX_APP_NUM = 32;
    public static final byte PART_MATCH = 0x00;
    public static final byte FULL_MATCH = 0x01;

    private byte[] AppName = new byte[33];
    private byte[] AID = new byte[17];
    private byte AidLen;
    private byte SelFlag;
    private byte Priority;
    private byte TargetPer;
    private byte MaxTargetPer;
    private byte FloorLimitCheck;
    private byte RandTransSel;
    private byte VelocityCheck;
    private int FloorLimit;
    private int Threshold;
    private byte[] TACDenial = new byte[6];
    private byte[] TACOnline = new byte[6];
    private byte[] TACDefault = new byte[6];
    private byte[] AcquierId = new byte[7];
    private byte[] dDOL = new byte[64];
    private byte[] tDOL = new byte[64];
    private byte[] Version = new byte[3];
    private byte[] RiskManData = new byte[10];
    private byte EC_bTermLimitCheck;
    private int EC_TermLimit;
    private byte CL_bStatusCheck;
    private int CL_FloorLimit;
    private int CL_TransLimit;
    private int CL_CVMLimit;
    private byte TermQuali_byte2;


    public EMVAPPLIST() {

    }


    public void parseFrom(byte[] APP) {

        System.arraycopy(APP, 0, AppName, 0, 33);

        System.arraycopy(APP, 33, AID, 0, 17);

        AidLen = APP[33 + 17];

        SelFlag = APP[33 + 17 + 1];

        Priority = APP[33 + 17 + 1 + 1];

        TargetPer = APP[33 + 17 + 1 + 1 + 1];

        MaxTargetPer = APP[33 + 17 + 1 + 1 + 1 + 1];

        FloorLimitCheck = APP[33 + 17 + 1 + 1 + 1 + 1 + 1];

        RandTransSel = APP[33 + 17 + 5 + 1];

        VelocityCheck = APP[33 + 17 + 5 + 1 + 1];


        byte[] b = new byte[4];
        System.arraycopy(APP, 33 + 17 + 8, b, 0, 4);
        FloorLimit = ByteTool.BytesToInt(b, 0);


        b = new byte[4];
        System.arraycopy(33 + 17 + 8 + 4, 0, b, 0, 4);
        Threshold = ByteTool.BytesToInt(b, 0);


        System.arraycopy(APP, 33 + 17 + 8 + 4 + 4, TACDenial, 0, 6);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 10, TACOnline, 0, 6);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 16, TACDefault, 0, 6);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 22, AcquierId, 0, 7);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29, dDOL, 0, 64);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64, tDOL, 0, 64);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64 + 64, Version, 0, 3);

        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3, RiskManData, 0, 10);

        EC_bTermLimitCheck = APP[33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 10];

        b = new byte[4];
        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11, b, 0, 4);
        EC_TermLimit = ByteTool.BytesToInt(b, 0);

        CL_bStatusCheck = APP[33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 4];


        b = new byte[4];
        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5, b, 0, 4);
        CL_FloorLimit = ByteTool.BytesToInt(b, 0);


        b = new byte[4];
        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5 + 4, b, 0, 4);
        CL_TransLimit = ByteTool.BytesToInt(b, 0);

        b = new byte[4];
        System.arraycopy(APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5 + 4 + 4, b, 0, 4);
        CL_CVMLimit = ByteTool.BytesToInt(b, 0);


        TermQuali_byte2 = APP[33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5 + 4 + 4 + 4];


    }

    public byte[] toBytes() {

        byte[] APP = new byte[251];

        System.arraycopy(AppName, 0, APP, 0, 33);

        System.arraycopy(AID, 0, APP, 33, 17);

        APP[33 + 17] = AidLen;

        APP[33 + 17 + 1] = SelFlag;

        APP[33 + 17 + 1 + 1] = Priority;

        APP[33 + 17 + 1 + 1 + 1] = TargetPer;

        APP[33 + 17 + 1 + 1 + 1 + 1] = MaxTargetPer;

        APP[33 + 17 + 1 + 1 + 1 + 1 + 1] = FloorLimitCheck;

        APP[33 + 17 + 5 + 1] = RandTransSel;

        APP[33 + 17 + 5 + 1 + 1] = VelocityCheck;

        byte[] b = ByteTool.intTo4bytes(FloorLimit);
        System.arraycopy(b, 0, APP, 33 + 17 + 8, 4);

        b = ByteTool.intTo4bytes(Threshold);
        System.arraycopy(b, 0, APP, 33 + 17 + 8 + 4, 4);

        System.arraycopy(TACDenial, 0, APP, 33 + 17 + 8 + 4 + 4, 6);

        System.arraycopy(TACOnline, 0, APP, 33 + 17 + 8 + 4 + 10, 6);

        System.arraycopy(TACDefault, 0, APP, 33 + 17 + 8 + 4 + 16, 6);

        System.arraycopy(AcquierId, 0, APP, 33 + 17 + 8 + 4 + 22, 7);

        System.arraycopy(dDOL, 0, APP, 33 + 17 + 8 + 4 + 29, 64);

        System.arraycopy(tDOL, 0, APP, 33 + 17 + 8 + 4 + 29 + 64, 64);

        System.arraycopy(Version, 0, APP, 33 + 17 + 8 + 4 + 29 + 64 + 64, 3);

        System.arraycopy(RiskManData, 0, APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3, 10);

        APP[33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 10] = EC_bTermLimitCheck;

        b = ByteTool.intTo4bytes(EC_TermLimit);
        System.arraycopy(b, 0, APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11, 4);

        APP[33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 4] = CL_bStatusCheck;

        b = ByteTool.intTo4bytes(CL_FloorLimit);
        System.arraycopy(b, 0, APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5, 4);

        b = ByteTool.intTo4bytes(CL_TransLimit);
        System.arraycopy(b, 0, APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5 + 4, 4);

        b = ByteTool.intTo4bytes(CL_CVMLimit);
        System.arraycopy(b, 0, APP, 33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5 + 4 + 4, 4);

        APP[33 + 17 + 8 + 4 + 29 + 64 + 64 + 3 + 11 + 5 + 4 + 4 + 4] = TermQuali_byte2;

        return APP;

    }

    public EMVAPPLIST(byte[] appName, byte[] aID, byte aidLen, byte selFlag,
                      byte priority, byte targetPer, byte maxTargetPer,
                      byte floorLimitCheck, byte randTransSel, byte velocityCheck,
                      int floorLimit, int threshold, byte[] tACDenial,
                      byte[] tACOnline, byte[] tACDefault, byte[] acquierId, byte[] dDOL,
                      byte[] tDOL, byte[] version, byte[] riskManData,
                      byte eC_bTermLimitCheck, int eC_TermLimit,
                      byte cL_bStatusCheck, int cL_FloorLimit, int cL_TransLimit,
                      int cL_CVMLimit, byte termQuali_byte2) {
        super();
        AppName = appName;
        AID = aID;
        AidLen = aidLen;
        SelFlag = selFlag;
        Priority = priority;
        TargetPer = targetPer;
        MaxTargetPer = maxTargetPer;
        FloorLimitCheck = floorLimitCheck;
        RandTransSel = randTransSel;
        VelocityCheck = velocityCheck;
        FloorLimit = floorLimit;
        Threshold = threshold;
        TACDenial = tACDenial;
        TACOnline = tACOnline;
        TACDefault = tACDefault;
        AcquierId = acquierId;
        this.dDOL = dDOL;
        this.tDOL = tDOL;
        Version = version;
        RiskManData = riskManData;
        EC_bTermLimitCheck = eC_bTermLimitCheck;
        EC_TermLimit = eC_TermLimit;
        CL_bStatusCheck = cL_bStatusCheck;
        CL_FloorLimit = cL_FloorLimit;
        CL_TransLimit = cL_TransLimit;
        CL_CVMLimit = cL_CVMLimit;
        TermQuali_byte2 = termQuali_byte2;
    }


    public byte[] getAppName() {
        return AppName;
    }

    public void setAppName(byte[] appName) {
        AppName = appName;
    }

    public byte[] getAID() {
        return AID;
    }

    public void setAID(byte[] aID) {
        AID = aID;
    }

    public byte getAidLen() {
        return AidLen;
    }

    public void setAidLen(byte aidLen) {
        AidLen = aidLen;
    }

    public byte getSelFlag() {
        return SelFlag;
    }

    public void setSelFlag(byte selFlag) {
        SelFlag = selFlag;
    }

    public byte getPriority() {
        return Priority;
    }

    public void setPriority(byte priority) {
        Priority = priority;
    }

    public byte getTargetPer() {
        return TargetPer;
    }

    public void setTargetPer(byte targetPer) {
        TargetPer = targetPer;
    }

    public byte getMaxTargetPer() {
        return MaxTargetPer;
    }

    public void setMaxTargetPer(byte maxTargetPer) {
        MaxTargetPer = maxTargetPer;
    }

    public byte getFloorLimitCheck() {
        return FloorLimitCheck;
    }

    public void setFloorLimitCheck(byte floorLimitCheck) {
        FloorLimitCheck = floorLimitCheck;
    }

    public byte getRandTransSel() {
        return RandTransSel;
    }

    public void setRandTransSel(byte randTransSel) {
        RandTransSel = randTransSel;
    }

    public byte getVelocityCheck() {
        return VelocityCheck;
    }

    public void setVelocityCheck(byte velocityCheck) {
        VelocityCheck = velocityCheck;
    }

    public int getFloorLimit() {
        return FloorLimit;
    }

    public void setFloorLimit(int floorLimit) {
        FloorLimit = floorLimit;
    }

    public int getThreshold() {
        return Threshold;
    }

    public void setThreshold(int threshold) {
        Threshold = threshold;
    }

    public byte[] getTACDenial() {
        return TACDenial;
    }

    public void setTACDenial(byte[] tACDenial) {
        TACDenial = tACDenial;
    }

    public byte[] getTACOnline() {
        return TACOnline;
    }

    public void setTACOnline(byte[] tACOnline) {
        TACOnline = tACOnline;
    }

    public byte[] getTACDefault() {
        return TACDefault;
    }

    public void setTACDefault(byte[] tACDefault) {
        TACDefault = tACDefault;
    }

    public byte[] getAcquierId() {
        return AcquierId;
    }

    public void setAcquierId(byte[] acquierId) {
        AcquierId = acquierId;
    }

    public byte[] getdDOL() {
        return dDOL;
    }

    public void setdDOL(byte[] dDOL) {
        this.dDOL = dDOL;
    }

    public byte[] gettDOL() {
        return tDOL;
    }

    public void settDOL(byte[] tDOL) {
        this.tDOL = tDOL;
    }

    public byte[] getVersion() {
        return Version;
    }

    public void setVersion(byte[] version) {
        Version = version;
    }

    public byte[] getRiskManData() {
        return RiskManData;
    }

    public void setRiskManData(byte[] riskManData) {
        RiskManData = riskManData;
    }

    public byte getEC_bTermLimitCheck() {
        return EC_bTermLimitCheck;
    }

    public void setEC_bTermLimitCheck(byte eC_bTermLimitCheck) {
        EC_bTermLimitCheck = eC_bTermLimitCheck;
    }

    public int getEC_TermLimit() {
        return EC_TermLimit;
    }

    public void setEC_TermLimit(int eC_TermLimit) {
        EC_TermLimit = eC_TermLimit;
    }

    public int getCL_bStatusCheck() {
        return CL_bStatusCheck;
    }

    public void setCL_bStatusCheck(byte cL_bStatusCheck) {
        CL_bStatusCheck = cL_bStatusCheck;
    }

    public int getCL_FloorLimit() {
        return CL_FloorLimit;
    }

    public void setCL_FloorLimit(int cL_FloorLimit) {
        CL_FloorLimit = cL_FloorLimit;
    }

    public int getCL_TransLimit() {
        return CL_TransLimit;
    }

    public void setCL_TransLimit(int cL_TransLimit) {
        CL_TransLimit = cL_TransLimit;
    }

    public int getCL_CVMLimit() {
        return CL_CVMLimit;
    }

    public void setCL_CVMLimit(int cL_CVMLimit) {
        CL_CVMLimit = cL_CVMLimit;
    }

    public byte getTermQuali_byte2() {
        return TermQuali_byte2;
    }

    public void setTermQuali_byte2(byte termQuali_byte2) {
        TermQuali_byte2 = termQuali_byte2;
    }

    public static int getMaxAppNum() {
        return MAX_APP_NUM;
    }

    public static byte getPartMatch() {
        return PART_MATCH;
    }

    public static byte getFullMatch() {
        return FULL_MATCH;
    }


}
